<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  
  <script>
    //与服务段建立连接
    var ws = new WebSocket('ws://localhost:3000')  
    //监听服务端发送过来的消息
    ws.onmessage = (message) => {
      console.log(message)
      //也可以给服务端发送消息
      ws.send('服务端你好啊！')
    }
  </script>
</body>
</html>